package com.etc.cloudalibaba.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.etc.cloud.entityes.CommonResult;

import java.util.Random;

/**
 * @Author kalista
 * @Description
 * @Date 2020/8/27  11:58
 **/
public class OrderServiceImpl  implements OrderService {

    @Override
    @SentinelResource(value = "getOrder", blockHandler = "handleException")
    public CommonResult getOrder() {
        return new CommonResult(0, String.valueOf(new Random().nextInt()));
    }

    public CommonResult handleException(BlockException ex) {
        return new CommonResult(-1,
                ex.getClass().getCanonicalName() + "\t服务不可用");
    }
}

